package com.example.demo3_viewpager2;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.example.demo3_viewpager2.fragment.AFragment;
import com.example.demo3_viewpager2.fragment.BFragment;
import com.example.demo3_viewpager2.fragment.CFragment;
import com.example.demo3_viewpager2.fragment.DFragment;

public class ViewPager2Adapter extends FragmentStateAdapter {
    public ViewPager2Adapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        switch (position){
            case 0:
                return new AFragment();
            case 1:
                return new BFragment();
            case 2:
                return new CFragment();
            case 3:
                return new DFragment();
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return 4;
    }
}
